<?php

namespace app\crm\controller;


use think\Controller;
use think\Db;

class Login extends Controller
{
    public function index(){
        return $this->fetch();
    }

    public function login()
    {
        $data = input('post.');
        $name = $data['username'];
        $pwd = $data['password'];
        $info = Db::name('admin')->where(['name' => $name])->find();
        $enc_pwd = encpwd($pwd, $info['salt']);
        if ($enc_pwd != $info['password']) {
            return json(['errorCode' => 1, 'msg' => '账号密码不正确']);
        }
        session('manage_user', $info['name']);
        session('manage_id', $info['id']);
        return json(['errorCode' => 0, 'msg' => '登录成功']);
    }

    public function logout(){
        session('manage_user',null);
        session('manage_id',null);
        $this->redirect('login/index');
    }

}